<template>
  <el-config-provider :locale="zhCn">
    <LowCode :schema="schema" />
  </el-config-provider>
</template>

<script setup>
import { watch, reactive } from 'vue'
import LowCode from '@/components/LowCode.vue'
import allBus from '@/core/bus'
import allLs from '@/core/ls'
import useBus from '@/core/hook/useBus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import { useRouter, useRoute } from 'vue-router'
import HomeSchema from './config/home'
import CostCustomerApi from './config/cost/customer/index'
import ConfigMenuSchema from './config/config/menu'
import ConfigDataMapSchema from './config/config/dataMap'
import ConfigPartnerInfoSchema from './config/config/partnerInfo'

const router = useRouter()
const route = useRoute()
useBus(() => {
  return allBus.common.loginSuccess.on((token) => {
    allLs.common.token.set(token)
    allLs.common.hasLogin.set(true)
    router.push('/')
  })
})
useBus(() => {
  return allBus.common.loginExpire.on(() => {
    allLs.common.token.remove()
    allLs.common.userInfo.remove()
    allLs.common.hasLogin.remove()
    router.push('/user/login')
  })
})

const schema = reactive({
  type: 'app',
  showAside: true,
  showHeader: true,
  pages: [
    {
      label: '首页',
      url: '/home',
      schema: () => import('./config/home')
    },
    {
      label: '低代码配置',
      url: '/lowcode',
      component: () => import('./views/lowCode/list.vue')
    },
    {
      label: '低代码配置',
      hidden: true,
      url: '/lowcode/operation',
      component: () => import('./views/lowCode/draggable/index.vue')
    },
    {
      label: '成本管理',
      url: '/cost',
      children: [
        {
          label: '获客成本',
          url: '/cost/customer',
          children: [
            {
              label: '获客成本-API',
              url: '/cost/customer/api',
              // schema: CostCustomerApi
              schemaApi: '/system/page/pageKey/vueLowCodeCostCustomerApiCost'
            }
          ]
        }
      ]
    },
    {
      label: '配置管理',
      url: '/config',
      children: [
        {
          label: '菜单功能配置',
          url: '/config/menu',
          // schema: ConfigMenuSchema,
          schemaApi: '/system/page/pageKey/vueLowCodeConfigMenu'
        },
        {
          label: '合作方信息配置',
          url: '/config/partnerInfo',
          // schema: ConfigPartnerInfoSchema
          schemaApi: '/system/page/pageKey/vueLowCodeConfigPartnerInfo'
        },
        {
          label: '数据源映射配置',
          url: '/config/dataMap',
          // schema: ConfigDataMapSchema
          schemaApi: '/system/page/pageKey/vueLowCodeConfigDataMap'
        }
      ]
    }
  ]
})

watch(
  () => route.path,
  (val) => {
    if (val === '/user/login') {
      schema.showAside = false
      schema.showHeader = false
    } else {
      schema.showAside = true
      schema.showHeader = true
    }
  },
  {
    immediate: true
  }
)
</script>

<style>
html,
body,
#app {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
}
body {
  overflow: hidden;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: #bfbfbf;
  border-radius: 10px;
}

.placeholder {
  color: #c8c9cc;
}

img {
  image-rendering: pixelated;
}

.el-dialog__body {
  max-height: 66vh;
  overflow: auto;
}

.h5-preview .el-dialog__body {
  overflow: hidden;
}
</style>
